package com.harmontronics.hanma.paas.paas.domain.app.repository.persistence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.harmontronics.hanma.paas.paas.domain.app.entity.valueobject.Fields;
import com.harmontronics.hanma.paas.paas.domain.app.repository.mapper.HmDatasourceEnvMapper;
import com.harmontronics.hanma.paas.paas.domain.app.repository.po.HmDatasourceEnvPO;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @author ldb
 */
@Repository("hmDatasourceEnvRepository")
public class HmDatasourceEnvRepository extends ServiceImpl<HmDatasourceEnvMapper, HmDatasourceEnvPO> {

    public IPage<HmDatasourceEnvPO> selectPage(QueryWrapper<HmDatasourceEnvPO> queryWrapper, Page<HmDatasourceEnvPO> page) {
        return baseMapper.selectPage(page, queryWrapper);
    }


    public void deleteByDatasourceId(Long datasourceId) {
        QueryWrapper<HmDatasourceEnvPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(Fields.DATASOURCE_ID, datasourceId);
        baseMapper.delete(queryWrapper);
    }

    public List<HmDatasourceEnvPO> findByDatasourceId(Long datasourceId) {
        QueryWrapper<HmDatasourceEnvPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(Fields.DATASOURCE_ID, datasourceId);
        return baseMapper.selectList(queryWrapper);
    }

    public List<HmDatasourceEnvPO> findByDatasourceIdIn(List<Long> datasourceIds) {
        QueryWrapper<HmDatasourceEnvPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(Fields.DATASOURCE_ID, datasourceIds);
        return baseMapper.selectList(queryWrapper);
    }
}